
import java.util.Random;
import java.util.Scanner;

public class Test1109_1 {
    public static void main(String[] args) {               //获取一个数的二进制序列中所有偶数位和奇数位， 分别输出二进制序列
        int num = 12;
        for (int i = 31; i >= 1; i -= 2) {                 //偶数位
            System.out.print(((num >> i) & 1) + " ");
        }
        System.out.println();
        for (int i = 30; i >= 0; i -= 2) {                 //奇数位
            System.out.print(((num >> i) & 1) + " ");
        }
    }

    public static void main11(String[] args) {              //输出一个整数的每一位，逆序
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int n = scan.nextInt();
        int tmp = 0;
        while (n != 0) {
            tmp = n % 10;
            System.out.print(tmp + " ");
            n /= 10;
        }

    }

    public static void main10(String[] args) {          //编写代码模拟三次密码输入的场景
        int count = 3;
        Scanner in = new Scanner(System.in);
        while (count != 0) {
            System.out.println("请输入您的密码：");
            String password = in.nextLine();            //输入有空格使用这个
            if (password.equals("123456")) {            //.equals 判断字符串是否相等
                System.out.println("登录成功！");
                break;
            }else {
                count--;
                System.out.println("密码错误！你还有" + count + "次机会");
            }
        }
    }

    public static void main9(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {               //循环输入并打印，按 ctrl+D 结束循环
            int a = in.nextInt();
            System.out.println(a);
        }
    }

    public static void main8(String[] args) {   //打印X形图案
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {               //多组输入
            int a = in.nextInt();
            for (int i = 0; i < a; i++) {
                for (int j = 0; j < a; j++) {
                    if (i == j || (i+j) == a-1) {
                        System.out.print("*");
                    } else {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }
    }

    public static void main7(String[] args) {
        Scanner scanner = new Scanner(System.in);

        Random random = new Random();
        int randNum = random.nextInt(100);          //[0,100)，生成0~100的随机数，不包括100

        while (true) {
            System.out.println("请输入数字进行猜数字游戏：");
            int n = scanner.nextInt();
            if (n > randNum) {
                System.out.println("猜大了！");
            } else if (n < randNum) {
                System.out.println("猜小了！");
            } else {
                System.out.println("恭喜你，猜对了！！！");
                return;                                     //结束程序
            }
        }
    }

    public static void main6(String[] args) {    //求出0~n之间的所有水仙花数并输出
        for (int i = 100; i <= 999; i++) {
            int tmp = i;
            int sum = 0;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10, 3);   //每次个位的立方和
                tmp /= 10;
            }
            if (sum == i) {
                System.out.println(i);
            }
        }
    }

    public static void main5(String[] args) {   //求出0~n之间的所有 自幂数 并输出
        for (int i = 0; i < 999999; i++) {      //n = 999999
            int count = 0;                      //存位数
            int tmp = i;                        //防止 i 的值丢失
            while (tmp != 0) {                  //求位数
                count++;
                tmp /= 10;                      //去掉个位
            }
            int sum = 0;
            tmp = i;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10, count);//每次个位的位数次方之和
                tmp /= 10;
            }
            if (sum == i) {
                System.out.println(i);
            }
        }
    }

    public static void main4(String[] args) {
        int a = 10;
        //System.out.println(!a);               //err，逻辑非！运算符只能结合布尔表达式，不能结合整型
    }

    public static void main3(String[] args) {   //给定一个数字，判定它是否是素数
        int n = 37;
        int i = 2;
        for ( ; i <= Math.sqrt(n); i++) {       //Math.sqrt(n) 求n的平方根；Math.pow(2，3) 求2的3次方
            if (n % i == 0) {
                System.out.println(n + " 不是素数");
                break;
            }
        }
        if (i > Math.sqrt(n)) {
            System.out.println(n + " 是素数");
        }
    }

    public static void main2(String[] args) {   // 1到100 的所有整数中出现多少个 包含9的数字
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 10 == 9) {
                count++;
            } else if (i / 10 == 9) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main1(String[] args) {   //编写程序数一下 1到100 的所有整数中出现多少个数字9
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 10 == 9) {
                count++;
            }
            if (i / 10 == 9) {
                count++;
            }
        }
        System.out.println(count);
    }
}

